package cn.ecut.tbjie.controller;

import cn.ecut.tbjie.annotation.NoToken;
import cn.ecut.tbjie.model.People;
import cn.ecut.tbjie.service.PeopleService;
import cn.ecut.tbjie.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "用户表接口")
@RequestMapping("/people")
public class PeopleController {
    @Autowired
    PeopleService service ;

    @ApiOperation(value = "添加用户")
    @PostMapping ("/addPeople")
    public JSONResult addPeople(People people){
        if(service.addPeople(people)){
            return JSONResult.ok("添加成功");
        }else{
            return JSONResult.errorMsg("添加失败，请查看信息是否完整");
        }
    }

    @ApiOperation(value = "查询所有用户表")
    @PostMapping ("/findAll")
    @ApiImplicitParam(name = "peopleId", required = true, type = "String",value = "用户Id")
    public JSONResult findAll(){
        List<People> list = service.findAll();
        if(list != null) {
            return JSONResult.ok(list);
        }else{
            return JSONResult.errorMsg("暂无数据");
        }
    }


}
